import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: '',
    redirect:'/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  },

  {
    path: '/layout',
    name: 'layout',
    // meta:{title:"充电站管理"} ,
    component: () => import('../views/Layout.vue'),
    redirect:'/home',
    children:[
      {
        path: '/home',
        name: 'home',
        meta:{title:'首页'},
        component: () => import('../views/menus/Home.vue')
      },
      { // 用户管理
        path: '/userList',
        name: 'userList',
        meta:{title:'用户列表'},
        component: () => import('../views/menus/UserManage/UserList.vue'),
      },
   
      {
        path: '/addFeeRules',
        name: 'addFeeRules',
        meta:{title:'新增费用规则'},
        component: () => import('../views/menus/GesStations/AddFeeRules/AddFeeRules.vue')
      },

      { // 用户管理
        path: '/UserDetail',
        name: 'UserDetail',
        meta:{title:'用户详情'},
        component: () => import('../views/menus/UserManage/UserDetail.vue')
      },
    ]
  },

  {
    path: '/gasStations',
    name: 'lGasStations',
    meta:{title:"充电站管理"} ,
    component: () => import('../views/Layout.vue'),
    children:[
          { // 充电站管理
            path: '/gasStations',
            name: 'gasStations',
            meta:{title:"充电站管理"} ,
            component: () => import('../views/menus/GesStations/GesStationsDeCharge.vue'),
          },
          { // 添加充电站
            path: '/addGesStation',
            name: 'addGesStation',
            meta:{title:"添加充电站"} ,
            component: () => import('../views/menus/GesStations/AddGesStation/AddGesStation.vue')
          },
          { // 充电桩
            path: '/ChargingPile',
            name: 'ChargingPile',
            meta:{title:'充电桩管理'},
            component: () => import('../views/menus/GesStations/ChargingPile.vue')
          },
          { // 添加充电桩
            path: '/addChargePile',
            name: 'addChargePile',
            meta:{title:'添加充电桩'},
            component: () => import('../views/menus/GesStations/AddChargePile/AddChargePile.vue')
          },
          {
            path: '/ChargingGun',
            name: 'ChargingGun',
            meta:{title:'充电枪管理'},
            component: () => import('../views/menus/GesStations/ChargingGun.vue')
          },
          {
            path: '/groundLock',
            name: 'groundLock',
            meta:{title:'地锁管理'},
            component: () => import('../views/menus/GesStations/GroundLock.vue')
          },
          {
            path: '/parkingSpace',
            name: 'parkingSpace',
            meta:{title:'停车位管理'},
            component: () => import('../views/menus/GesStations/ParkingSpace.vue')
          },
          {
            path: '/feeRules',
            name: 'feeRules',
            meta:{title:'费用规则'},
            component: () => import('../views/menus/GesStations/FeeRules.vue')
          },
      ]
    },
  {
    path: '/placeholder',
    name: 'lPlaceholder',
    meta:{title:"订单管理"} ,
    component: () => import('../views/Layout.vue'),
    children:[
      { // 订单管理
        path: '/placeholder',
        name: 'placeholder',
        meta:{title:'占位订单'},
        component: () => import('../views/menus/OrderManage/Placeholder.vue')
      },
      { // 订单管理
        path: '/chargingDetail',
        name: 'chargingDetail',
        meta:{title:'详情'},
        component: () => import('../views/menus/OrderManage/ChargingDetail/ChargingDetail.vue')
      },
      {
        path: '/charging',
        name: 'charging',
        meta:{title:'充电订单'},
        component: () => import('../views/menus/OrderManage/Charging.vue')
      },
      {
        path: '/placeholderDetail',
        name: 'placeholderDetail',
        meta:{title:'详情'},
        component: () => import('../views/menus/OrderManage/PlaceholderDetail/PlaceholderDetail.vue')
      },
      {
        path: '/drawback',
        name: 'drawback',
        meta:{title:'退款记录'},
        component: () => import('../views/menus/OrderManage/Drawback.vue')
      },
      {
        path: '/withdrawPlaceholder',
        name: 'withdrawPlaceholder',
        meta:{title:'占位订单-详情'},
        component: () => import('../views/menus/OrderManage/WithdrawDetail/WithdrawPlaceholder.vue')
      },
      {
        path: '/withdrawCharging',
        name: 'withdrawCharging',
        meta:{title:'充电订单-详情'},
        component: () => import('../views/menus/OrderManage/WithdrawDetail/WithdrawCharging.vue')
      },
    ]
    },
    {
      path: '/recharge',
      name: 'lRecharge',
      meta:{title:"资产管理"} ,
      component: () => import('../views/Layout.vue'),
      children:[
        { // 资产管理
          path: '/recharge',
          name: 'recharge',
          meta:{title:'充值管理'},
          component: () => import('../views/menus/AssetManage/RechargeRecord.vue')
        },
        {
          path: '/withdraw',
          name: 'withdraw',
          meta:{title:'提现管理'},
          component: () => import('../views/menus/AssetManage/WithdrawRecord.vue')
        },
      ]
    },
    {
      path: '/alarmCenter',
      name: 'lAlarmCenter',
      meta:{title:"运营监测"} ,
      component: () => import('../views/Layout.vue'),
      children:[
        { // 运营监测
          path: '/alarmCenter',
          name: 'alarmCenter',
          meta:{title:'告警中心'},
          component: () => import('../views/menus/OperationMonitoring/AlarmCenter.vue')
        },
        {
          path: '/troubleshooting',
          name: 'troubleshooting',
          meta:{title:'故障报修'},
          component: () => import('../views/menus/OperationMonitoring/Troubleshooting.vue')
        },
      ]
    },
    {
      path: '/bannerManage',
      name: 'lBannerManage',
      meta:{title:"运营管理"} ,
      component: () => import('../views/Layout.vue'),
      children:[
        { // 运营管理
          path: '/bannerManage',
          name: 'bannerManage',
          meta:{title:'banner管理'},
          component: () => import('../views/menus/OperationManage/BannerManage.vue')
        },
        {
          path: '/helpCenter',
          name: 'helpCenter',
          meta:{title:'帮助中心'},
          component: () => import('../views/menus/OperationManage/HelpCenter.vue')
        },
      ]
    },
    {
      path: '/couponManage',
      name: 'lCouponManage',
      meta:{title:"营销管理"} ,
      component: () => import('../views/Layout.vue'),
      children:[
        { // 营销管理
          path: '/couponManage',
          name: 'couponManage',
          meta:{title:'优惠券管理'},
          component: () => import('../views/menus/MarketingManage/CouponManage.vue')
        },
        { // 营销管理
          path: '/couponDetail',
          name: 'couponDetail',
          meta:{title:'优惠券详情'},
          component: () => import('../views/menus/MarketingManage/CouponDetail.vue')
        },
        { // 营销管理
          path: '/addCoupon',
          name: 'addCoupon',
          meta:{title:'新增优惠券'},
          component: () => import('../views/menus/MarketingManage/AddCoupon.vue')
        },
      ]
    },
    {
      path: '/accountSetting',
      name: 'lAccountSetting',
      meta:{title:"系统设置"} ,
      component: () => import('../views/Layout.vue'),
      children:[
        { // 系统设置
          path: '/accountSetting',
          name: 'accountSetting',
          meta:{title:'账户管理'},
          component: () => import('../views/menus/SystemSettings/AccountSetting.vue')
        },
        {
          path: '/roleManage',
          name: 'roleManage',
          meta:{title:'角色管理'},
          component: () => import('../views/menus/SystemSettings/RoleManage.vue')
        },
        {
          path: '/departmentManage',
          name: 'departmentManage',
          meta:{title:'部门管理'},
          component: () => import('../views/menus/SystemSettings/DepartmentManage.vue')
        },
        {
          path: '/logManage',
          name: 'logManage',
          meta:{title:'日志管理'},
          component: () => import('../views/menus/SystemSettings/LogManage.vue'),
        },
        { // 登录日志
          path: '/loginManage',
          name: 'loginManage',
          meta:{title:'登录日志'},
          component: () => import('../views/menus/SystemSettings/logs/LoginManage.vue')
        },
        { // 操作日志
          path: '/OperateManage',
          name: 'OperateManage',
          meta:{title:'操作日志'},
          component: () => import('../views/menus/SystemSettings/logs/OperateManage.vue')
        },
        {
          path: '/basicSettings',
          name: 'basicSettings',
          meta:{title:'基本设置'},
          component: () => import('../views/menus/SystemSettings/BasicSettings.vue')
        },
        {
          path: '/personalInformation',
          name: 'personalInformation',
          meta:{title:'个人信息'},
          component: () => import('../views/menus/SystemSettings/PersonalInformation.vue')
        },
      ]
    },
]

// const originalPush = VueRouter.prototype.push

// VueRouter.prototype.push = function push(location) {

//   return originalPush.call(this,location).catch(err => err)

// }




// 先把vueRouter原型对象的push、replace保存一份
let originPush = VueRouter.prototype.push
let originReplace = VueRouter.prototype.replace
// 重写push和replace
// 第一个参数，告诉原来push方法，往哪里跳转，传递哪些参数
// 第二个参数是成功的回调
// 第三个参数是失败的回调
VueRouter.prototype.push = function(location,resolve,reject){
  if(resolve && reject){
    // call和apply区别
    // 相同点：都可以调用函数一次，都可以篡改函数的上下文一次
    // 不同点：call和apply传递参数：call传递参数用逗号隔开，apply方法传递数组
    originPush.call(this,location,resolve,reject)
  }else{
    originPush.call(this,location,() => {}, () => {})
  }
}
VueRouter.prototype.replace = function(location,resolve,reject){
  if(resolve && reject){
    originReplace.call(this,location,resolve,reject)
  }else{
    originReplace.call(this,location,() => {}, () => {})
  }
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
 
// router.beforeEach(()=>{

// })
export default router
